
<%@page import="entityclasses.roles"%>
<%@page import="entityclasses.event"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Date"%>
<%-- 
    Document : createelection.jsp
    author : Mishal Parmar
    Date   : 21 Oct 2012
--%>

<%@page import="entityclasses.election"%>
<%@page import="controllers.modifyElectdata"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="java.util.ArrayList"%>


<!DOCTYPE html>
<html>
    <head>


        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="eventpage/images/main.css"/>
        <script type="text/javascript" language="javascript" src="eventpage/images/prototype-1.js"></script>
        <script type="text/javascript" language="javascript" src="eventpage/images/prototype-base-extensions.js"></script>
        <script type="text/javascript" language="javascript" src="eventpage/images/prototype-date-extensions.js"></script>
        <script type="text/javascript" language="javascript" src="eventpage/images/behaviour.js"></script>
        <script type="text/javascript" language="javascript" src="eventpage/images/datepicker.js"></script>
        <link rel="stylesheet" href="eventpage/images/datepicker.css"/>

        <script type="text/javascript" language="javascript" src="eventpage/images/behaviors.js"></script>

    </head>
    <body>
        <%
            modifyElectdata modify = new modifyElectdata();

            election elect = new election();

            event evt = new event();
            roles role = new roles();
            roles userrole = new roles();

            ArrayList electarray = new ArrayList();
            ArrayList evtarray = new ArrayList();
            ArrayList rolearray = new ArrayList();
            ArrayList userrolearray = new ArrayList();

            Object electdata = request.getAttribute("electdata");
            Object evtdata = request.getAttribute("eventdata");
            Object accessuser = request.getAttribute("accessdata");
            Object userrol = request.getAttribute("userroledata");

            electarray = (ArrayList<election>) electdata;
            evtarray = (ArrayList<election>) evtdata;
            rolearray = (ArrayList<election>) accessuser;
            userrolearray = (ArrayList<election>) userrol;

            elect = (election) electarray.get(0);
            evt = (event) evtarray.get(0);
            role = (roles) rolearray.get(0);


            java.util.Date dt = new java.util.Date();
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String currentTime = sdf.format(dt);

            DateFormat formatter;

            Date date;
            formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            String[] datetime = {elect.getStart_time(),
                elect.getEnd_time(),
                elect.getNominee_start(),
                elect.getNominee_end()};
            for (int i = 0; i < 4; i++) {

                date = (Date) formatter.parse(datetime[i]);
                java.text.SimpleDateFormat datefor = new java.text.SimpleDateFormat("MM-dd-yyyy HH:mm");
                String timedate = datefor.format(date);
                datetime[i] = timedate;
            }
            //elect.setStart_time("10-11-2012 15:02");
            // elect.setEnd_time("10-11-2012 15:02");
            // elect.setNominee_end("10-11-2012 15:02");
            //elect.setNominee_start("10-11-2012 15:02");
            out.println("<h1> Election List </h1> <table border=1>");
        %>

        <h2> Modify Election </h2>
        <form name="modifyelection" method="post" action="modifyElectdata">

            <div style="float:left; width:100px; margin-left: 30px;">Voting start</div> 
            <input name="starttime" id="starttime" value='<%=datetime[0]%>' class="datetimepicker"/>
            <br clear="all"/><br />

            <div style="float:left; width:100px; margin-left: 30px;">Voting End</div> 
            <input name="endtime" id="endtime" class="datetimepicker" value='<%=datetime[1]%>' />
            <br clear="all"/><br />

            <div style="float:left; width:100px; margin-left: 30px;">Nominee start</div> 
            <input name="nomineestart" id="nomineestart" class="datetimepicker"  value='<%=datetime[2]%>'/>
            <br clear="all"/><br />

            <div style="float:left; width:100px; margin-left: 30px;">Nominee End</div> 
            <input type="text" name="nomineeend" id="nomineeend" class="datetimepicker" value='<%=datetime[3]%>'/>
            <br clear="all"/><br />

            <div style="float:left; width:100px; margin-left: 30px;">Event Member</div> 
            <div>
                <%
                    for (int i = 0; i < userrolearray.size(); i++) {

                        userrole = (roles) userrolearray.get(i);
                        if (userrole.getRole_id() == role.getRole_id()) {

                %>
                <input type="radio" name="accesstype" checked value="<%=userrole.getRole_id()%>" /><%=userrole.getRole_name()%>  
                <%
                        } else {
                            out.println("<input type='radio' name='accesstype' value='" + userrole.getRole_id() + "' />" + userrole.getRole_name());
                        }
                    }
                %>
            </div>
            <br clear="all"/><br />
            <div> <input type="hidden" name="electid" value="<%=elect.getElect_id()%>"/></div>
            <div> <input type="hidden" name="eventid" value="<%=evt.getEventId()%>"/></div>
            <div style="margin-left: 50px; margin-top: 10px;">
                <br/>
                <input type="submit" value="update" name="modifydata"/>
            </div>   
        </form>


    </body>
</html>
